home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-23 | 2.2 KB | 64 lines | [TEXT/GEOL] |
- Item 9466606 20-March-90 09:47PST
-
- From: ROSENSTEIN1 Rosenstein, Larry
-
- To: CPLUS.APPLE$ C++ Interest List--Apple Employees
- CPLUS.DEV$ C++ Interest List--Developers
- MACAPP.TECH$ MacApp Technical
- APPLE.BUGS Apple Bugs Reporting
-
- Sub: C/C++ BUG
-
- Attn: C++ Apple
- Attn: C++ Public
- Attn: MacApp Tech
- Attn: Apple Bugs
- SentBy: Larry Rosenstein
- Subject: C/C++ BUG 3/19/90 9:55 AM
- There's a subtle C compiler bug that you might run into while using C++
- (especially if you are using it with MacApp). The bug is demonstrated by the
- program at the end.
-
- If you compile this and dump the object code for the TestBug routine, you will
- see that the compiler places the result of the GetRect call into a local
- variable, and then tries to copy that local into r. Unfortunately, when it
- does the copy it uses the wrong local variable.
-
- It is difficult to characterize the kind of C++ code that causes the bug. It
- is necessary that you call a function with Pascal calling conventions that
- returns a value larger than 4 bytes. It is also seems necessary to have a
- statement where CFront must create a temporary variable. (Take a look at the
- generated C code to see what I mean.)
-
- In the example below, the result of GetFoo is assigned to a CFront-generated
- temporary variable, before GetRect is called. If you assigne the result to an
- explicit local variable, then the output from the C compiler is OK. The same
- is true if you remove the word 'pascal' from the declaration of GetRect.
-
- This is a bug in the C compiler, but the code that causes the problem is
- relatively obscure, and seems likely to appear only if you are using C++.
- Also, since it is necessary to use Pascal calling conventions, it is most
- likely to affect programmers trying to interface C++ and Pascal.
-
- Larry Rosenstein
-
-
- #include <Types.h>
-
- class TFoo: public PascalObject {
- public:
- virtual pascal Rect GetRect();
- };
-
- class TBar: public PascalObject {
- public:
- virtual pascal TFoo* GetFoo();
- };
-
- pascal void TestBug(TBar* aBar)
- {
- Rect r = (aBar -> GetFoo()) -> GetRect();
- }
-
-
-